home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 8: LINUX Games / Linux Cubed Series 8 - LINUX Games.iso / games / x11 / networke / xfirepow.000 / xfirepow / xfirepower-0.84 / client / motd.c < prev    next >
C/C++ Source or Header  |  1996-03-16  |  2KB  |  118 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <ctype.h>
  5. #include "data.h"
  6. #include "struct.h"
  7. #include "defs.h"
  8.  
  9. static char **motd=0;
  10. static int motdLines=0, maxMotd=0, motdPage = 0;
  11.  
  12. void add_motd_line(int line, char *text)
  13. {
  14.     while(line >= maxMotd) {
  15.         maxMotd += 10;
  16.         if(motd) {
  17.             motd = realloc(motd, maxMotd * sizeof(char *));
  18.         } else
  19.             motd = malloc(maxMotd * sizeof(char *));
  20.     }
  21.  
  22.     motd[motdLines] = malloc(100);
  23.     strncpy(motd[motdLines], text, 100);
  24.     motdLines++;
  25.  
  26.     redrawMotd = 1;
  27. }
  28.  
  29. void display_motd()
  30. {
  31.     int i, bold;
  32.     W_Color color;
  33.     int max;
  34.     char *ptr;
  35.  
  36.     redrawMotd = 0;
  37.     if(!motdwin) {
  38.         motdwin = W_MakeTextWindow("Motd", 0, 0, 80, LINESPERPAGE, 0, 0, 0);
  39.         W_Buffer(motdwin, 0);
  40.         W_MapWindow(motdwin);
  41.     }
  42.  
  43.     W_ClearWindow(motdwin);
  44.  
  45.     if(motdLines < (motdPage+1) * LINESPERPAGE)
  46.         max = motdLines;
  47.     else
  48.         max = (motdPage+1) * LINESPERPAGE;
  49.  
  50.     for(i=motdPage * LINESPERPAGE;i<max;i++) {
  51.         color = W_White;
  52.         bold = 0;
  53.         ptr = motd[i];
  54.         if(motd[i][0] == '\\') {
  55.             ptr = &motd[i][2];
  56.             switch(motd[i][1]) {
  57.             case 'r':
  58.             case 'R':
  59.                 color = W_Red;
  60.                 break;
  61.             case 'b':
  62.             case 'B':
  63.                 color = W_Blue;
  64.                 break;
  65.             case 'g':
  66.             case 'G':
  67.                 color = W_Green;
  68.                 break;
  69.             case 'y':
  70.             case 'Y':
  71.                 color = W_Yellow;
  72.                 break;
  73.             case 'c':
  74.             case 'C':
  75.                 color = W_Cyan;
  76.                 break;
  77.             case 'e':
  78.             case 'E':
  79.                 color = W_Grey;
  80.                 break;
  81.             default:
  82.                 color = W_White;
  83.                 break;
  84.             }
  85.             if(isupper(motd[i][1]))
  86.                 bold = 1;
  87.         }
  88.         W_WriteText(motdwin, 0, i % (LINESPERPAGE), color, ptr,
  89.                     strlen(ptr), bold ? W_BoldFont : W_RegularFont);
  90.     }
  91. }
  92.  
  93. void motd_key(int key)
  94. {
  95.     switch(key) {
  96.     case ' ':
  97.         if(me->p_status != POUTFIT) {
  98.             W_DestroyWindow(motdwin);
  99.             motdwin = 0;
  100.         }
  101.         return;
  102.     case 'f':
  103.         if(((motdPage+1) * LINESPERPAGE ) < motdLines) {
  104.             motdPage++;
  105.             display_motd();
  106.         }
  107.         return;
  108.     case 'b':
  109.         if(motdPage > 0) {
  110.             motdPage--;
  111.             display_motd();
  112.         }
  113.         return;
  114.     }
  115. }
  116.  
  117.         
  118.